package com.yxq.mdt.app.modules.picturebrowse.ui;

import android.os.Bundle;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.viewpager.widget.ViewPager;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.luck.picture.lib.photoview.PhotoView;
import com.yxq.mdt.app.R;
import com.yxq.mdt.app.base.BaseActivity;
import com.yxq.mdt.app.constant.RouteTable;
import com.yxq.mdt.app.modules.picturebrowse.adapter.PicturePageAdapter;

import java.util.List;

import butterknife.BindView;

/**
 * @author L
 * @time
 * @describe 图片浏览-查看大图
 */
@Route(path = RouteTable.ROUTER_ACTIVITY_PICTURE)
public class PictureActivity extends BaseActivity {

    @BindView(R.id.photo_view)
    PhotoView photoView;
    @BindView(R.id.view_pager)
    ViewPager viewPager;
    @BindView(R.id.tv_indicator)
    TextView tvIndicator;
    PicturePageAdapter picturePageAdapter;
    private int position = 1;

    @Override
    public int getLayoutId() {
        setEnableImmersion(true);
        setStatusBarColor(R.color.colorPrimary);
        return R.layout.activity_picture;
    }

    @Override
    public void initView() {

    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        //查看图片在数组中的位置
        position = getIntent().getIntExtra("position", 1);
        //图片数组
        List<String> basePictureBeanList = getIntent().getStringArrayListExtra("images");
        tvIndicator.setText(String.format("%d/%d", (position + 1), basePictureBeanList.size()));
        //初始化图片适配器
        picturePageAdapter = new PicturePageAdapter(this,getSupportFragmentManager(), basePictureBeanList);
        viewPager.setAdapter(picturePageAdapter);
        viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                //更新下标
                tvIndicator.setText(String.format("%d/%d", (position + 1), basePictureBeanList.size()));
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
        //选中当前下标图片
        viewPager.setCurrentItem(position);
        //单击图片退出当前界面
        picturePageAdapter.setPicturePageInterface(() -> PictureActivity.this.finish());
    }


}
